<template>
	<view>
		<u-navbar title="我的帖子" :background="{ background: '#a0cfff' }" title-color="#FFFFFF"></u-navbar>
		<view class="invnBox">
			<view class="invnSin" v-for="(item,index) in invnList" :key="index">
				<view class="title">{{item.title}}</view>
				<view class="cosntent">
					{{item.content}}
				</view>
				<view class="look">{{item.look}}人观看</view>
				<view class="bottom">
					<u-button size="mini" type="error" @click="deleteClick(item.id)">删除</u-button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import helper from '../../common/helper.js'
	export default {
		data() {
			return {
				invnList: []
			}
		},
		created() {
			this.getInvn()
		},
		methods: {
			getInvn(){
				let that = this
				let user = uni.getStorageSync("user")
				let data = {
					query: '',
					pageNum: 1,
					pageSize: -1,
					userId: user.id
				}
				that.getRequest(helper.getInvn,data).then(res => {
					if(res.data.flag == "200"){
						let serve = res.data.invnList
						that.invnList = []
						serve.forEach((item,index) => {
							if(item.fileUrl.indexOf("<<tupian>>") > 0){
								item.fileUrl = item.fileUrl.split("<<tupian>>")
								// console.log(index)
								let obj = item.fileUrl
								that.$set(item,'fUrl',obj)
								// console.log(obj)
							}else{
								let obj = []
								that.$set(item,'fUrl',obj)
							}
							item.creatTime = that.formatDateTime(item.creatTime)
							// console.log(item.shopUrl)
							that.invnList.push(item)
						})
					}
				})
			},
			deleteClick(index){
				let that = this
				uni.showModal({
					title: '提示',
					content: '是否取消收藏该商品？',
					success: function (res) {
						if (res.confirm) {
							let data = {
								id: index,
							}
							that.postRequest(helper.getDelete, data).then(res => {
								if (res.data.flag == "200") {
									uni.showToast({
										title: '删除成功',
										icon: 'none',
										duration: 2000
									})
									that.getInvn()
								} else {
									uni.showToast({
										title: '删除失败',
										icon: 'none',
										duration: 2000
									})
								}
							})
						} else if (res.cancel) {
							uni.showToast({
								title: '删除失败',
								icon: 'none',
								duration: 2000
							})
						}
					}
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
.invnBox{
	.invnSin{
		padding: 40rpx 30rpx;
		border-bottom: 1rpx #F1F1F1 solid;
		.title{
			font-size: 32rpx;
			font-weight: bold;
		}
		.look{
			margin-top: 10rpx;
			color: #BBBCBE;
			font-size: 24rpx;
		}
		.bottom{
			margin-top: 15rpx;
			display: flex;
			justify-content: flex-end;
		}
	}
}
</style>
